package org.example.admin.controller;

import lombok.RequiredArgsConstructor;
import org.example.admin.common.convention.result.Result;
import org.example.admin.common.convention.result.Results;
import org.example.admin.dto.req.GroupSortReqDTO;
import org.example.admin.dto.req.GroupUpdateReqDTO;
import org.example.admin.dto.resp.GroupBaseDTO;
import org.example.admin.service.GroupService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author weibin
 * @since 2025/10/4 18:29
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin")
public class GroupController {

    private final GroupService groupService;

    @PostMapping("/saveGroup")
    public Result<Void> saveGroup(@RequestParam("groupName") String groupName) {
        groupService.saveGroup(groupName);
        return Results.success();
    }

    @GetMapping("/listGroup")
    public Result<List<GroupBaseDTO>> listGroup() {
        return Results.success(groupService.listGroup());
    }

    @PostMapping("/updateGroup")
    public Result<Void> updateGroup (@RequestBody GroupUpdateReqDTO requestParam) {
        groupService.updateGroup(requestParam);
        return Results.success();
    }

    @GetMapping("/deleteGroup")
    public Result<Void> deleteGroup(@RequestParam("gid") String gid) {
        groupService.deleteGroup(gid);
        return Results.success();
    }

    @PostMapping("/sortGroup")
    public Result<Void> sortGroup(@RequestBody List<GroupSortReqDTO> requestParam) {
        groupService.sortGroup(requestParam);
        return Results.success();
    }
}
